package com.code.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.code.domain.Houses;
import com.code.model.Result;
import com.code.service.HousesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "房屋管理接口")
public class HouseController {

    @Autowired
    private HousesService housesService;

    @GetMapping("search")
    @ApiOperation("分页搜索房屋信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "page", value = "当前页码", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "city", value = "城市", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "content", value = "搜索内容", dataType = "String", paramType = "query"),
    })
    public Result<Page<Houses>> searchHouses(Integer page, String city, String content) {
        Page<Houses> housesPage = housesService.searchHousesByPage(page, city, content);
        return Result.success("ok",housesPage);
    }

    @GetMapping("details")
    @ApiOperation("根据id查询房屋具体信息")
    @ApiImplicitParam(name = "id", value = "房屋id", dataType = "Integer", paramType = "query")
    public Result<Houses> getHouseDetails(Integer id) {
        Houses houses = housesService.getById(id);
        return Result.success("ok", houses);
    }
}
